#include "mainwindow.h"

#include <QApplication>
#include <QLocale>
#include <QTranslator>
#include <QDebug>
#include <QFile>
#include <QTextStream>
#include <QDialog>

#include "globaluserlist.h"

#define endl Qt::endl

void initData();
int main(int argc, char *argv[])
{
    initData();
    QApplication a(argc, argv);
    MainWindow w;
    w.show();

    return a.exec();
}

void initData() {
    QFile userFile("userData.txt");
    if (userFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
        QTextStream out(&userFile);
        out.setCodec("UTF-8");
        for (int i = 100; i <= 109; i++) {
            out << i << endl
                << "user" << i % 100 << endl
                << "user" << i % 100 << endl
                << 100 + (i + 8) % 10 << endl
                << 100 + (i + 7) % 10 << endl
                << endl;
        }
        userFile.close();
        // 处理文件内容
    } else {
        // 文件无法打开
        qDebug() << "userData文件打开失败" << endl;
    }

    QFile logFile1("logChat-user1.txt");
    if (logFile1.open(QIODevice::WriteOnly | QIODevice::Text)) {
        QTextStream out(&logFile1);
        out.setCodec("UTF-8");
        out << "2019-07-14 user1: " << endl
            << QString("你好, 我是user2") << endl;
        out << "2020-12-21 user2: " << endl
            << QString("好久不见") << endl;
        logFile1.close();
    } else {
        qDebug() << "logFile1文件打开失败" << endl;
    }

    globaluserlist& glbuserlist = globaluserlist::getInstance();

}
